﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net;
using SimpleBlog.ViewModels;
using SimpleBlog.Helpers;
using SimpleBlog.Mvc;

namespace SimpleBlog.Controllers
{
    [ErrorView]
    public class ErrorController : Controller
    {
        public ActionResult Index(HttpException exception)
        {
            HttpStatusCode code = (HttpStatusCode)exception.GetHttpCode();
            string errorMessage = null;
            string shortMessage = null;
            switch (code)
            {
                case HttpStatusCode.NotFound:
                    errorMessage = "Page Not Found. Check the URL in your browser and try again.";
                    shortMessage = "Page Not Found";
                    break;
                case HttpStatusCode.InternalServerError:
                    errorMessage = "An error has occured while process your request. Please try again.";
                    shortMessage = "Server Error";
                    break;
                default:
                    errorMessage = "An error has occured. Please try again.";
                    shortMessage = code.ToString().SplitUpperCaseToString();
                    break;
            }
            return View("Index", new ErrorViewModel()
            {
                Code = (int)code,
                Message = errorMessage,
                ShortMessage = shortMessage
            });
        }
    }
}
